<?php
    $title = $titulo = 'Liquidaciones';

   	$mipath='../';
   	include ('../inc/config.php');
    $de_donde = '';

	if (!isset($_SESSION["admin"])) {redirect("login.php");	exit(); }

	if(!empty($_SESSION['Msg'])) {
		echo '<center><div style="width:90%;height:30px;background-color:lightblue;border:2px solid blue;font-size:16px;font-weight;bold;text-align:center;margin-top:5px;padding-top:5px;color:blue;">';
		echo $_SESSION['Msg']."</div></center>";
		$_SESSION['Msg']='';
	}
    
	$tlipre        = request('tlipre',0);

	//--- Busco el codigo administrativo, y traigo los datos del usuario
	$rs  = $db->SelectLimit("select * from usuarios_codigos where codigo='$tlipre'",1);
	$Usuario = $rs->FetchRow();

	if (!$Usuario) { echo "<h1>Código Administrativo inexistente!!</h1>"; die(); }

	$ano         = request('ano',date("Y"));
	$mes         = request('mes',date("m"));
	$correlativo = request('correlativo',1);
	$periodo     = $ano.$mes;



	
?>
<html>
<head>
	<link href="<?php echo ADMIN;?>css_admin.css" rel="stylesheet" type="text/css"/>
    <script src="<?php echo URL;?>/js/ui/development-bundle/jquery-1.7.2.js"></script>
    <script type="text/javascript" src="<?php echo URL;?>/js/ui/js/jquery-ui-1.8.21.custom.min.js"></script>    
	<script type="text/javascript" src="<?php echo URL;?>/js/jquery-validation-1.9.0/jquery.validate.js"></script>
    <script type="text/javascript" src="<?php echo URL;?>/js/jquery-validation-1.9.0/localization/messages_es.js"></script>
	<link rel="stylesheet" href="<?php echo URL;?>/css/formularios.css" type="text/css" media="screen" />
</head>
<body style='padding:20px;'>

<form action='ver_liquidacion.php' method='post'>
<table style='width:950px;'>
	<tr>
		<td colspan='2'>
			<h2><?php echo $Usuario['nombre'];?> [<?php echo $Usuario['username'];?>] -> Cta.Admin.: <?php echo $Usuario['codigo'];?></h2>
		</td>
	</tr>
	<tr>
		<td>Periodo: Año: 
			<?php 
			    $desde = 2011;
			    $hasta = date("Y",time());
			    $cb_ano = "<select name='ano'>";
			    for ( $i = $hasta ; $i >= $desde ; $i --) {
			     if($ano==$i){$sel = 'selected=selected';} else {$sel='';}
			     $cb_ano.= "<option value='$i' $sel>$i</option>";   
			    }    
			    $cb_ano.= "</select>";
			    echo $cb_ano;
			?>    	
			&nbsp;&nbsp;&nbsp;&nbsp;
			Mes: <select name='mes'>
				<option value='01' <?php if ($mes==1){echo 'selected';}?> >Enero</option>
				<option value='02' <?php if ($mes==2){echo 'selected';}?> >Febrero</option>
				<option value='03' <?php if ($mes==3){echo 'selected';}?> >Marzo</option>
				<option value='04' <?php if ($mes==4){echo 'selected';}?> >Abril</option>
				<option value='05' <?php if ($mes==5){echo 'selected';}?> >Mayo</option>
				<option value='06' <?php if ($mes==6){echo 'selected';}?> >Junio</option>
				<option value='07' <?php if ($mes==7){echo 'selected';}?> >Julio</option>
				<option value='08' <?php if ($mes==8){echo 'selected';}?> >Agosto</option>
				<option value='09' <?php if ($mes==9){echo 'selected';}?> >Septiembre</option>
				<option value='10' <?php if ($mes==10){echo 'selected';}?> >Octubre</option>
				<option value='11' <?php if ($mes==11){echo 'selected';}?> >Noviembre</option>
				<option value='12' <?php if ($mes==12){echo 'selected';}?> >Diciembre</option>	
			</select>

			&nbsp;&nbsp;&nbsp;&nbsp;
			Nro.Liquidación del Mes: <select name='correlativo'>
				<option value='1' <?php if ($correlativo==1){echo 'selected';}?> >01</option>
				<option value='2' <?php if ($correlativo==2){echo 'selected';}?> >02</option>
				<option value='3' <?php if ($correlativo==3){echo 'selected';}?> >03</option>
				<option value='4' <?php if ($correlativo==4){echo 'selected';}?> >04</option>
			</select>

		</td>
		<td>
			<input type='hidden' value='<?php echo $tlipre;?>' name='tlipre'>
			<input type='submit' value='Buscar Liquidación' style='padding:5px;' name='submit'>
		</td>
	</tr>
</table>
<hr>
</form>


<?php

	if ($_POST['submit']) {
		$sql = "select * from liquidaciones where 
				tlipre = '$tlipre' and tliper='$periodo' and correlativo='$correlativo' 
				order by id ASC";
		$rs  = 	$db->Execute($sql);
		$Liqui = $rs->GetRows();
		
		if ($Liqui) {
			echo "<h3>Liquidación Nro: {$Liqui[0]['tlinli']} - {$Liqui[0]['tlinpe']}</h3>";

?>
			<table style='width:950px;font-family:"Courier"; font-size:11px;'>
				<tr style='background:#dcdcdc;'>
					<th colspan='2' >CONCEPTO</th>
					<th>FECHA</th>
					<th>PRESTATARIO</th>
					<th colspan='3'>COMPROBANTE</th>
					<th>F.COMP</th>
					<th>PORC.</th>
					<th>IMPORTE</th>
					<th>COMENTARIO</th>
				</tr>	

<?php			
			foreach($Liqui as $l){
	            $t_honorarios_exentos  = $t_honorarios_exentos + $l['tlihex'];
	            $t_honorarios_gravados = $t_honorarios_gravados + $l['tlihgr'];
	            $t_desgloses_exentos   = $t_desgloses_exentos + $l['tlidex'];
	            $t_desgloses_gravados  = $t_desgloses_gravados + $l['tlidgr'];
	            $t_bruto_exento        = $t_bruto_exento + $l['tlibex'];
	            $t_bruto_gravado       = $t_bruto_gravado + $l['tlibgr'];
	            $t_descuentos          = $t_descuentos + $l['tlides'];
	            $t_creditos            = $t_creditos + $l['tlicre'];
	            $t_iva_terceros        = $t_iva_terceros + $l['tliiv3'];
	            $t_desgloses_iva       = $t_desgloses_iva + $l['tlidiv'];
	            $t_retencion_ganancia  = $t_retencion_ganancia + $l['tligan'];
	            $t_ingresos_brutos     = $t_ingresos_brutos + $l['tlibru'];
	            $t_total_neto          = $t_total_neto + $l['tliimp'];

?>
				<tr>
					<td><?php echo $l['tlicod'];?></td>
					<td><?php echo $l['tlinco'];?></td>
					<td><?php echo $l['tlifec'];?></td>
					<td><?php echo $l['tlinos'];?></td>
					<td><?php echo $l['tlitip'];?></td>
					<td><?php echo $l['tlisuc'];?></td>
					<td><?php echo $l['tlinro'];?></td>
					<td><?php echo $l['tliffa'];?></td>
					<td style='text-align:right;'><?php echo $l['tlipor'];?></td>
					<td style='text-align:right;'><?php echo $l['tliimp'];?></td>
					<td><?php echo $l['tlitxt'];?></td>
				</tr>	
<?php
			} // end foreach
?>
				</table>	
			<br>	
			<table style='width:950px;font-family:"Courier"; font-size:11px;background:#dcdcdc;'>
				<tr><td colspan='10' style='font-size:13px;font-weight:bold;'>SubTotales de Liquidación</td></tr>
				<tr>
					<th>Honorarios<br>Exentos</th>
					<th>Honorarios<br>Gravados</th>
					<th>Desgloses<br>Exentos</th>
					<th>Desgloses<br>Gravados</th>
					<th>Total Bruto<br>Exento</th>
					<th>Total Bruto<br>Gravado</th>
					<th>Descuentos</th>
					<th>Créditos</th>
					<th>I.V.A.<br>Terceros</th>
					<th>Desgloses<br>I.V.A.</th>
				</tr>	
				<tr>
					<td style='text-align:center;'><?php echo number_format($t_honorarios_exentos,2);?></td>
					<td style='text-align:center;'><?php echo number_format($t_honorarios_gravados,2);?></td>
					<td style='text-align:center;'><?php echo number_format($t_desgloses_exentos,2);?></td>
					<td style='text-align:center;'><?php echo number_format($t_desgloses_gravados,2);?></td>
					<td style='text-align:center;'><?php echo number_format($t_bruto_exento,2);?></td>
					<td style='text-align:center;'><?php echo number_format($t_bruto_gravado,2);?></td>
					<td style='text-align:center;'><?php echo number_format($t_descuentos,2);?></td>
					<td style='text-align:center;'><?php echo number_format($t_creditos,2);?></td>
					<td style='text-align:center;'><?php echo number_format($t_iva_terceros,2);?></td>
					<td style='text-align:center;'><?php echo number_format($t_desgloses_iva,2);?></td>
					
				</tr>	
				<tr>
					<td colspan='8' style='font-size:13px;font-weight:bold;text-align:right;'>SubTotal Neto</td>
					<td colspan='2' style='text-align:center;font-size:13px;font-weight:bold;'>
						<?php echo number_format($t_total_neto,2);?>.-$
					</td>
				</tr>
			</table>	
<?php


		} else { // endif($Liqui)
			echo "<h1>Liquidación Inexistente!!</h1>";
		}

	} else {
		die();		
	}
    
    

?>


</body></html>